<!-- 系统日志 -->
<template>
    <div class="journal">
        <el-card class="!border-none" shadow="never">
            <el-form ref="formRef" class="mb-[-16px]" :model="formData" :inline="true">
                <el-form-item label="关键词">
                    <el-input
                        style="width:300px;"
                        placeholder="请输入ip,appid,调用域名"
                        v-model="formData.keyword"
                        clearable
                        @keyup.enter="resetPage"
                    />
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="resetPage"
                        >查询</el-button
                    >
                    <el-button @click="resetParams">重置</el-button>
                    <el-button @click="yjql">一键清理</el-button>
                </el-form-item>
            </el-form>
        </el-card>

        <el-card class="!border-none mt-4" shadow="never" v-loading="pager.loading">
            <div>
                <el-table :data="pager.lists" size="large">
                    <el-table-column label="调用域名" prop="id" min-width="180">
                        <template #default="{ row }">
                            {{row.data.redirect_uri}}
                        </template>
                    </el-table-column>
                    <el-table-column label="ip" prop="ip" min-width="120" >
                        <template #default="{ row }">
                            {{row.data.ip}}
                        </template>
                    </el-table-column>
                    <el-table-column label="appid" prop="appid" min-width="120" >
                        <template #default="{ row }">
                            {{row.data.appid}}
                        </template>
                    </el-table-column>
                    <el-table-column label="接口类型" prop="admin_id" min-width="120">
                        <template #default="{ row }">
                            <span v-if="row.type == 1">
                                授权
                            </span>
                            <span v-if="row.type == 2">
                                消息转发
                            </span>
                        </template>
                    </el-table-column>
                    <el-table-column label="日志内容" prop="admin_id" min-width="120">
                        <template #default="{ row }" >
                            <el-button @click="seecontent(row)" link type="primary" v-if="row.type == 2 && row.data.xml != undefined">查看</el-button>
                        </template>
                    </el-table-column>
                    <el-table-column label="记录时间" prop="create_time" min-width="160">
                        <template #default="{ row }">
                            {{row.create_time}}
                        </template>
                    </el-table-column>
                </el-table>
            </div>
            <div class="flex mt-4 justify-end">
                <pagination v-model="pager" @change="getLists" />
            </div>
        </el-card>
        <el-dialog v-model="contenting" title="日志内容" width="40%">
            <p class="wspl">
                {{content}}
            </p>
            <template #footer>
                <span class="dialog-footer">
                    <el-button type="primary" @click="contenting = false">
                        确定
                    </el-button>
                </span>
            </template>
        </el-dialog>
    </div>
</template>

<script setup lang="ts" name="journal">
import {  recordList,recordClear,recordSwitchGet,recordSwitch } from '@/api/application/gzh/index'
import { usePaging } from '@/hooks/usenew'
import feedback from '@/utils/feedback'

// 查询表单
const formData = ref({
    keyword:""
})
const yjql = async() => {
    await feedback.confirm("确定要清除？");
    await recordClear({})
    getLists()
}
const contenting = ref(false)
const content = ref("")
const seecontent = (row:any) =>{
    content.value = row.data.xml
    contenting.value = true
}
const { pager, getLists, resetParams, resetPage } = usePaging({
    fetchFun: recordList,
    params: formData.value
})
const switching = ref(1)
const getData = async() => {
    const data = await recordSwitchGet({})
    switching.value = data.switch
}
const changeswitch = async(type:any) => {
    console.log(type)
    if(type == 0){
        await recordSwitch({switch:type})
    }else{
        await recordSwitch({switch:type})
    }
    getLists()
    getData()
}
getData()
onMounted(() => {
    getLists()
})
</script>

<style lang="scss" scoped>
.wspl {
    white-space: pre-wrap;
    background: rgba(0, 0, 0, 0.3);
}
</style>
